<?php

// default configuration. These values can be changed
// via the admin page, so you do not need to edit them here
// they are used to initialise things
// if you *do* edit them, make sure they stay in the correct format
// otherwise you will end up with parse errors and things will stop working

if (!defined('PHPLISTINIT')) {
    die;
}

$defaultheader = '</head><body>';

$defaultfooter = '</body></html>';

if (is_file(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/frontendheader.php')) {
    $defaultheader = file_get_contents(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/frontendheader.php');
}
if (is_file(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/frontendfooter.php')) {
    $defaultfooter = file_get_contents(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/frontendfooter.php');
}

$envHost = getEnv('HOSTNAME');
$envPort = getEnv('PORT');
if (isset($_SERVER['HTTP_HOST'])) {
    $D_website = $_SERVER['HTTP_HOST'];
} elseif (isset($_SERVER['SERVER_NAME'])) {
    $D_website = $_SERVER['SERVER_NAME'];
} elseif(!empty($envHost)) {
    if ($envPort != 80 && $envPort != 443) {
        $D_website = "$envHost:$envPort";
    } else {
        $D_website = "$envHost";
    }
} else {
    $D_website = s('unable to detect hostname');
}

$D_domain = $D_website;
if (preg_match("#^www\.(.*)#i", $D_domain, $regs)) {
    $D_domain = $regs[1];
}

// for starters, you want to leave this line as it is.
$default_config = array(

    /* any next line has the format
      "name" => array(
        'value',     // default value
        'description',
        'type',      // text, textarea, boolean
        'allow empty', // 0 or 1 (or false/true)
        'category'   // 常规
      ),
    */

    // what is your website location (url)
    'website' => array(
        'value'       => $D_website,
        'description' => s('网址（不含http://）'),
        'infoicon'    => true,
        'type'        => 'text',
        'allowempty'  => false, //# indication this value cannot be empty (1 being it can be empty)
        'category'    => '常规',
    ),

    // what is your domain (for sending emails)
    'domain' => array(
        'value'       => $D_domain,
        'description' => s('服务器的域名（用于电子邮件）'),
        'type'        => 'text',
        'allowempty'  => false,
        'category'    => '常规',
    ),

    // admin address is the person who is in charge of this 系统
    'admin_address' => array(
        'value'       => 'webmaster@[DOMAIN]',
        'description' => s('系统负责人（一个电子邮件地址）'),
        'type'        => 'email',
        'allowempty'  => false,
        'category'    => '常规',
    ),
    // name of the organisation
    'organisation_name' => array(
        'value'       => '',
        'description' => s('组织名称'),
        'type'        => 'text',
        'allowempty'  => true,
        'allowtags'   => '<b><i><u><strong><em><h1><h2><h3><h4>',
        'allowJS'     => false,
        'category'    => '常规',
    ),
// logo of the organisation
    'organisation_logo' => array(
        'value'       => '',
        'description' => s('Logo'),
        'infoicon'    => true,
        'type'        => 'image',
        'allowempty'  => true,
        'category'    => '常规',
    ),
    'date_format' => array(
        'value'       => 'j F Y',
        'description' => s('日期格式'),
        'infoicon'    => true,
        'type'        => 'text',
        'allowempty'  => false,
        'category'    => '常规',
    ),
    'rc_notification' => array(
        'value'       => 0,
        'description' => s('显示发布候选者的通知'),
        'type'        => 'boolean',
        'allowempty'  => true,
        'category'    => '安全',
    ),

    //# remote processing secret
    // @TODO previous value generation was limited to 20 hex characters (max), determine if this is enough (80 bits)
    'remote_processing_secret' => array(
        'value'       => bin2hex(random_bytes(10)),
        'description' => s('远程处理的安全'),
        'type'        => 'text',
        'category'    => '安全',
    ),

    // admin addresses are other people who receive copies of 订阅s
    'admin_addresses' => array(
        'value'       => '',
        'description' => s('抄送的电子邮件地址列表系统消息（用逗号分隔）'),
        'type'        => 'emaillist',
        'allowempty'  => true,
        'category'    => '发布',
    ),
    '邮件from_default' => array(
        'value'       => '',
        'description' => s("默认发件的邮箱"),
        'type'        => 'text',
        'allowempty'  => true,
        'category'    => '邮件',
    ),
    'notifystart_default' => array(
        'value'       => '',
        'description' => s("发送开始时要提醒的邮箱地址"),
        'type'        => 'email',
        'allowempty'  => true,
        'category'    => '邮件',
    ),
    'notifyend_default' => array(
        'value'       => '',
        'description' => s("发送完成时要提醒的邮箱地址"),
        'type'        => 'email',
        'allowempty'  => true,
        'category'    => '邮件',
    ),
    'always_add_googletracking' => array(
        'value'       => '0',
        'description' => '添加分析跟踪代码',
        'type'        => 'boolean',
        'allowempty'  => true,
        'category'    => '邮件',
    ),
    'analytic_tracker' => array(
        'values'       => array('google' => 'Google Analytics', 'matomo' => 'Matomo'),
        'value'        => 'google',
        'description'  => s('要添加的分析跟踪代码的URL'),
        'type'         => 'select',
        'allowempty'   => false,
        'category'     => '邮件',
    ),
    // report address is the person who gets the reports
    'report_address' => array(
        'value'       => 'listreports@[DOMAIN]',
        'description' => s('获得报告的电子邮件地址，多封电子邮件用逗号分隔'),
        'type'        => 'emaillist',
        'allowempty'  => true,
        'category'    => '发布',
    ),

    // where will messages appear to come from
    'message_from_address' => array(
        'value'       => 'noreply@[DOMAIN]',
        'description' => s('系统消息的发件人电子邮件地址'),
        'type'        => 'email',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    'message_from_name' => array(
        'value'       => s('Webmaster'),
        'description' => s('系统消息的名称'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // what is the reply-to on messages?
    'message_replyto_address' => array(
        'value'       => 'noreply@[DOMAIN]',
        'description' => s('回复的电子邮件地址系统消息'),
        'type'        => 'email',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // if there is only one visible list, do we hide it and automatically
    // subscribe users who sign up
    //# not sure why you would not want this :-) maybe it should not be an option at all
    'hide_single_list' => array(
        'value'       => '1',
        'description' => s('如果只有一个可见列表，是否应将其隐藏在页面中并自动订阅注册的用户'),
        'type'        => 'boolean',
        'allowempty'  => true,
        'category'    => '订阅页面ui',
    ),

    // categories for lists, to organise them a little bit
    // comma separated list of words
    'list_categories' => array(
        'value'       => '',
        'description' => s('列表的类别。用逗号分隔。'),
        'infoicon'    => true,
        'type'        => 'text',
        'allowempty'  => true,
        'category'    => '列表组织',
    ),

    'displaycategories' => array(
        'value'       => 0,
        'description' => s('在订阅页面上显示列表类别'),
        'type'        => 'boolean',
        'allowempty'  => false,
        'category'    => '订阅列表',
    ),

    // width of a textline field
    'textline_width' => array(
        'value'       => '40',
        'description' => s('文本行字段的宽度（数字）'),
        'type'        => 'integer',
        'min'         => 20,
        'max'         => 150,
        'category'    => '订阅页面ui',
    ),

    // dimensions of a textarea field
    'textarea_dimensions' => array(
        'value'       => '10,40',
        'description' => s('文本区域字段的维度（行、列)'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '订阅页面ui',
    ),

    // send copies of subscribe, update unsubscribe messages to the administrator
    'send_admin_copies' => array(
        'value'       => '0',
        'description' => s('发送有关订阅、更新和取消订阅的通知'),
        'type'        => 'boolean',
        'allowempty'  => true,
        'category'    => '发布',
    ),

    // the main subscribe page, when there are multiple
    'defaultsubscribepage' => array(
        'value'       => 1,
        'description' => s('当存在多个订阅时的默认订阅页面'),
        'type'        => 'integer',
        'min'         => 1,
        'max'         => 999,  // max(id) from subscribepage
        'allowempty'  => true,
        'category'    => '订阅',
    ),

    // the default template for sending an html message
    'defaultmessagetemplate' => array(
        'value'       => 0,
        'description' => s('发送邮件时使用的默认HTML模板'),
        'type'        => 'text',
        'allowempty'  => true,
        'category'    => '邮件',
    ),

    // the template for 系统 messages (welcome confirm subscribe etc)
    '系统messagetemplate' => array(
        'value'       => 0,
        'description' => s('HTML模板的系统消息'),
        'type'        => 'integer',
        'min'         => 0,
        'max'         => 999, // or max(id) from template
        'allowempty'  => true,
        'category'    => '模版',
    ),
    //# the location of your subscribe script
    //"public_baseurl" => array("http://[WEBSITE]$pageroot/",
    //  "Base URL for public pages","text"),

    // the location of your subscribe script
    'subscribeurl' => array(
        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=subscribe",
        'description' => s('订阅者可以注册的URL'),
        'type'        => 'url',
        'allowempty'  => 0,
        'category'    => '订阅',
    ),

    // the location of your unsubscribe script:
    'unsubscribeurl' => array(
        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=unsubscribe",
        'description' => s('URL where subscribers can unsubscribe'),
        'type'        => 'url',
        'allowempty'  => 0,
        'category'    => '订阅',
    ),

    //0013076: Blacklisting posibility for unknown users
    // the location of your blacklist script:
    'blacklisturl' => array(
        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=donotsend",
        'description' => s('未知用户可以取消订阅的URL（不发送列表）'),
        'type'        => 'url',
        'allowempty'  => 0,
        'category'    => '订阅',
    ),

// the location of your confirm script:
    'confirmationurl' => array(
        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=confirm",
        'description' => s('订阅者必须在其中确认其订阅'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '订阅',
    ),

    // url to change their preferences
    'preferencesurl' => array(
        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=preferences",
        'description' => s('订阅者可以更新其详细信息的URL'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '订阅',
    ),

    // url to change their preferences
    'forwardurl' => array(
        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=forward",
        'description' => s('用于转发消息的URL'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '订阅',
    ),

    // url to download vcf card
    'vcardurl' => array(
        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=vcard",
        'description' => s('下载vcf卡片的URL'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '订阅',
    ),

    'ajax_subscribeconfirmation' => array(
        'value'       => s('<h3>Thanks, you have been added to our newsletter</h3><p>You will receive an email to confirm your 订阅. Please click the link in the email to confirm</p>'),
        'description' => s('要显示的文本订阅 AJAX请求成功'),
        'type'        => 'textarea',
        'allowempty'  => true,
        'category'    => '订阅',
    ),

    // the location of your subscribe script
    //"subscribe_baseurl" => array("http://[WEBSITE]$pageroot/",
    //  "Base URL for public pages","text"),

    // the subject of the message
    'subscribesubject' => array(
        'value'       => s('Request for confirmation'),
        'description' => s('订阅者注册时收到的消息的主题'),
        'infoicon'        => true,
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // message that is sent when people sign up to a list
    // [LISTS] will be replaced with the list of lists they have signed up to
    // [CONFIRMATIONURL] will be replaced with the URL where a user has to confirm
    // their 订阅
    'subscribemessage' => array(
        'value' =>
' You have been subscribed to the following newsletters:

[LISTS]


Please click the following link to confirm it\'s really you:

[CONFIRMATIONURL]


In order to provide you with this service we\'ll need to

Transfer your contact information to [DOMAIN]
Store your contact information in your [DOMAIN] account
Send you emails from [DOMAIN]
Track your interactions with these emails for marketing purposes

If this is not correct, or you do not agree, simply take no action and delete this message.'
    ,
        'description' => s('Message subscribers receive when they sign up'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // subject of the message when they unsubscribe
    'unsubscribesubject' => array(
        'value'       => s('Goodbye from our Newsletter'),
        'description' => s('订阅者取消订阅时收到的消息的主题'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // message that is sent when they unsubscribe
    'unsubscribemessage' => array(
        'value' =>
'Goodbye from our Newsletter, sorry to see you go.

You have been unsubscribed from our newsletters.

This is the last email you will receive from us. Our newsletter 系统, phpList,
will refuse to send you any further messages, without manual intervention by our administrator.

If there is an error in this information, you can re-subscribe:
please go to [SUBSCRIBEURL] and follow the steps.

Thank you'
  ,
        'description' => s('消息订阅者在取消订阅时收到'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // confirmation of 订阅
    'confirmationsubject' => array(
        'value'       => s('Welcome to our Newsletter'),
        'description' => s('订阅者确认电子邮件地址后收到的邮件的主题'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // message that is sent to confirm 订阅
    'confirmationmessage' => array(
        'value' =>
'Welcome to our Newsletter

Please keep this message for later reference.

Your email address has been added to the following newsletter(s):
[LISTS]

To update your details and preferences please go to [PREFERENCESURL].
If you do not want to receive any more messages, please go to [UNSUBSCRIBEURL].

Thank you'
  ,
        'description' => s('订阅者在确认其电子邮件地址后收到的消息'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // the subject of the message sent when changing the user details
    'updatesubject' => array(
        'value'       => s('[notify] Change of List-Membership details'),
        'description' => s('订阅者更改详细信息时收到的消息的主题'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // the message that is sent when a user updates their information.
    // just to make sure they approve of it.
    // confirmationinfo is replaced by one of the options below
    // userdata is replaced by the information in the database
    'updatemessage' => array(
        'value' =>
'This message is to inform you of a change of your details on our newsletter database

You are currently member of the following newsletters:

[LISTS]

[CONFIRMATIONINFO]

The information on our 系统 for you is as follows:

[USERDATA]

If this is not correct, please update your information at the following location:

[PREFERENCESURL]

Thank you'
  ,
        'description' => s('消息订阅者更改详细信息后会收到消息'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // this is the text that is placed in the [!-- confirmation --] location of the above
    // message, in case the email is sent to their new email address and they have changed
    // their email address
    'emailchanged_text' => array(
        'value' => '
  When updating your details, your email address has changed.
  Please confirm your new email address by visiting this webpage:

  [CONFIRMATIONURL]

  ',
        'description' => s('当订阅者更改其信息并且电子邮件地址已更改时，发送到其新电子邮件地址的邮件的一部分'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    // this is the text that is placed in the [!-- confirmation --] location of the above
    // message, in case the email is sent to their old email address and they have changed
    // their email address
    'emailchanged_text_oldaddress' => array(
        'value' =>
'Please Note: when updating your details, your email address has changed.

A message has been sent to your new email address with a URL
to confirm this change. Please visit this website to activate
your membership.'
  ,
        'description' => s('当订阅者更改其信息并且电子邮件地址已更改时，发送到其旧电子邮件地址的邮件的一部分'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    'personallocation_subject' => array(
        'value'       => s('Your personal location'),
        'description' => s('订阅者请求其个人位置时的消息主题'),
        'type'        => 'text',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    'personallocation_message' => array(
        'value' =>
'You have requested your personal location to update your details in our newsletter database.
The location is below. Please make sure that you use the full line as mentioned below.
Sometimes email programs wrap the link over multiple lines.

Your personal location is:
[PREFERENCESURL]

Thank you.'
  ,
        'description' => s('订阅者请求其个人位置时的消息'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    'messagefooter' => array(
        'value' => '

    <div class="footer" style="text-align:left; font-size: 75%;">
      <p>This message was sent to [EMAIL] by [FROMEMAIL].</p>
      <p>To forward this message, please do not use the forward button of your email application, because this message was made specifically for you only. Instead use the <a href="[FORWARDURL]">forward page</a> in our newsletter 系统.<br/>
      To change your details and to choose which lists to be subscribed to, visit your personal <a href="[PREFERENCESURL]">preferences page</a>.<br/>
      Or you can <a href="[UNSUBSCRIBEURL]">opt-out completely</a> from all future mailings.</p>
    </div>

  ',
        'description' => s('发送邮件的默认页脚'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '邮件',
    ),

    'forwardfooter' => array(
        'value' => '
     <div class="footer" style="text-align:left; font-size: 75%;">
      <p>This message has been forwarded to you by [FORWARDEDBY].</p>
      <p>You have not been automatically subscribed to this newsletter.</p>
      <p>If you think this newsletter may interest you, you can <a href="[SUBSCRIBEURL]">Subscribe</a> and you will receive our next newsletter directly to your inbox.</p>
      <p>You can also <a href="[BLACKLISTURL]">opt out completely</a> from receiving any further email from our newsletter application.</p>
    </div>
  ',
        'description' => s('转发消息时使用的页脚'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '邮件',
    ),

    'pageheader' => array(
        'value'       => $defaultheader,
        'description' => s('公共页面的头部'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '订阅-ui',
    ),

    'pagefooter' => array(
        'value'       => $defaultfooter,
        'description' => s('公共页面的页脚'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '订阅-ui',
    ),

//"html_charset" => array (
    //"UTF-8",
    //"Charset for HTML messages",
    //"text"
//),
//"text_charset" => array (
    //"UTF-8",
    //"Charset for Text messages",
    //"text"
//),

    'personallocation_message' => array(
        'value' =>

'You have requested your personal location to update your details from our website.
The location is below. Please make sure that you use the full line as mentioned below.
Sometimes email programmes can wrap the line into multiple lines.

Your personal location is:
[PREFERENCESURL]

Thank you.'
,
        'description' => s('当请求个人位置时要发送的消息'),
        'type'        => 'textarea',
        'allowempty'  => 0,
        'category'    => '模版',
    ),

    'remoteurl_append' => array(
        'value'       => '',
        'description' => s('使用发送网页时始终附加到远程URL的字符串'),
        'type'        => 'text',
        'allowempty'  => true,
        'category'    => '邮件',
    ),

    'wordwrap' => array(
        'value'       => '75',
        'description' => s('文字信息的自动换行宽度'),
        'type'        => 'text',
        'allowempty'  => true,
        'category'    => '邮件',
    ),

    'html_email_style' => array(
        'value'       => '',
        'description' => s('用于没有模板的HTML消息的CSS'),
        'type'        => 'textarea',
        'allowempty'  => true,
        'category'    => '邮件',
    ),

    'alwayssendtextto' => array(
        'value'       => '',
        'description' => s('只接受文本电子邮件的域，每行一个'),
        'type'        => 'textarea',
        'allowempty'  => true,
        'category'    => '邮件',
    ),

    'tld_last_sync' => array(
        'value'       => '0',
        'description' => s('上次提取TLDS的时间'),
        'type'        => 'text',
        'allowempty'  => true,
        'category'    => '系统',
        'hidden'      => true,
    ),
    'internet_tlds' => array(
        'value'       => '',
        'description' => s('顶级域名'),
        'type'        => 'textarea',
        'allowempty'  => true,
        'category'    => '系统',
        'hidden'      => true,
    ),

);

//######### certainly do not edit after this #########

$redfont = '';
$efont = '';

if (!TEST && REGISTER && defined('VERSION')) {
    if (strpos(VERSION, 'dev') !== false) {
        $v = 'dev';
    } else {
        $v = VERSION;
    }
    $PoweredBy = '<p align="left"><a href="https://www.jikelogistics.com"><img src="https://www.jikelogistics.com/template/default/images/logo.png" width="80" height="31" title="powered by jikelogistics" alt="powered by jikelogistics" border="0" /></a></p>';
} else {
    $PoweredBy = '<center><a href="https://www.jikelogistics.com"><img src="images/power-phplist.png" width="80" height="31" title="powered by jikelogistics" alt="powered by jikelogistics" border="0" /></a></center>';
}

if (!function_exists('getconfig')) {
    function getConfig($item)
    {
        global $default_config, $domain, $website, $tables;

        if ($item != 'website' && isset($GLOBALS['config'][$item])) {
            return $GLOBALS['config'][$item];
        }
        /*
            if (!DEVSITE && isset($_SESSION['config'][$item])) {
              return $_SESSION['config'][$item];
            }
        */
        if (!isset($GLOBALS['config']) || !is_array($GLOBALS['config'])) {
            $GLOBALS['config'] = array();
        }

        if (empty($_SESSION['hasconf'])) {
            $hasconf = Sql_Table_Exists($tables['config'], 1);
            $_SESSION['hasconf'] = $hasconf;
        } else {
            $hasconf = $_SESSION['hasconf'];
        }

        $value = '';
        if (!empty($hasconf)) {
            $req = Sql_Query(sprintf('select value,editable from %s where item = "%s"', $tables['config'],
                sql_escape($item)));
            if (!Sql_Affected_Rows() || !$hasconf) {
                if (isset($default_config[$item])) {
                    $value = $default_config[$item]['value'];
                }
                // save the default value to the database, so we can obtain
                // the information when running from commandline
                if (Sql_Table_Exists($tables['config'])) {
                    saveConfig($item, $value);
                }
                //    print "$item => $value<br/>";
            } else {
                $row = Sql_Fetch_Row($req);
                $value = $row[0];
                if (!empty($default_config[$item]['hidden'])) {
                    $GLOBALS['noteditableconfig'][] = $item;
                }
            }
        }
        $value = str_replace('[WEBSITE]', $website, $value);
        $value = str_replace('[DOMAIN]', $domain, $value);
        $value = str_replace('<?=VERSION?>', VERSION, $value);

        if (isset($default_config[$item]['type'])) {
            $type = $default_config[$item]['type'];
        } else {
            $type = '';
        }

        if ($type == 'boolean') {
            if ($value == '0') {
                $value = 'false';
            } elseif ($value == '1') {
                $value = 'true';
            }
            //# cast to bool
            $value = $value == 'true';
        }

        //# disallow single quotes in listcategories
        if ($item == 'list_categories') {
            $value = str_replace("'", ' ', $value);
        }

        // if this is a subpage item, and no value was found get the global one
        if (!$value && strpos($item, ':') !== false) {
            list($a, $b) = explode(':', $item);
            $value = getConfig($a);
            $_SESSION['config'][$item] = $value;

            return $value;
        } else {
            $GLOBALS['config'][$item] = stripslashes($value);
            $_SESSION['config'][$item] = $GLOBALS['config'][$item];

            return $GLOBALS['config'][$item];
        }
    }
} else {
    reset($default_config);
    foreach ($default_config as $item => $values) {
        $val = getConfig($item);
        saveConfig($item, $values[0], 0);
    }
}

function getUserConfig($item, $userid = 0)
{
    global $default_config, $tables, $domain, $website;
    $hasconf = Sql_Table_Exists($tables['config']);
    $value = '';

    if ($hasconf) {
        $req = Sql_Query(sprintf('select value,editable from %s where item = "%s"', $tables['config'],
            sql_escape($item)));

        if (!Sql_Num_Rows($req)) {
            if (array_key_exists($item, $default_config)) {
                $value = $default_config[$item]['value'];
            }
        } else {
            $row = Sql_fetch_Row($req);
            $value = $row[0];

            if ($row[1] == 0) {
                $GLOBALS['noteditableconfig'][] = $item;
            }
        }
    }
    // if this is a subpage item, and no value was found get the global one
    if (!$value && strpos($item, ':') !== false) {
        list($a, $b) = explode(':', $item);
        $value = getUserConfig($a, $userid);
    }

    if ($userid) {
        $rs = Sql_Query(sprintf('select uniqid, email from '.$tables['user'].' where id = %d', $userid));
        $user_req = Sql_Fetch_Row($rs);
        $uniqid = $user_req[0];
        $email = $user_req[1];
        // parse for placeholders
        // do some backwards compatibility:
        // hmm, reverted back to old 系统

        $url = getConfig('unsubscribeurl');
        $sep = strpos($url, '?') !== false ? '&' : '?';
        $value = str_ireplace('[UNSUBSCRIBEURL]', $url.$sep.'uid='.$uniqid.' ', $value);
        $url = getConfig('confirmationurl');
        $sep = strpos($url, '?') !== false ? '&' : '?';
        $value = str_ireplace('[CONFIRMATIONURL]', $url.$sep.'uid='.$uniqid.' ', $value);
        $url = getConfig('preferencesurl');
        $sep = strpos($url, '?') !== false ? '&' : '?';
        $value = str_ireplace('[PREFERENCESURL]', $url.$sep.'uid='.$uniqid.' ', $value);
        $value = str_ireplace('[EMAIL]', $email, $value);

        $value = parsePlaceHolders($value, getUserAttributeValues($email));
    }
    $value = str_ireplace('[SUBSCRIBEURL]', getConfig('subscribeurl').' ', $value);
    $value = preg_replace('/\[DOMAIN\]/i', $domain,
        $value); //@ID Should be done only in one place. Combine getConfig and this one?
    $value = preg_replace('/\[WEBSITE\]/i', $website, $value);

    if ($value == '0') {
        $value = 'false';
    } elseif ($value == '1') {
        $value = 'true';
    }

    return $value;
}

$access_levels = array(
    0 => 'none',
    1 => 'all',
    2 => 'view',
    //   3 => "edit",
    4 => 'owner',
);
